// import './css/index.css';
window.onload = function() {
    const baseURL = "http://www.rushmc.top/api/";
    const queryURL = "http://www.rushmc.top/api/";
    var idname = '';
    var user = "";
    var Photo = "";
    var Phone = "";
    var Id = "";
    var state = "";
    var tran = document.getElementsByClassName("tran ");
    var logging = document.getElementsByClassName("logging");
    for (var i = 0; i < tran.length; i++) {
        tran[i].num = i;
        tran[i].addEventListener("click", function() {
            var index = this.num;
            // 设置类让选中的页面透明
            logging[index].className = "logging hidden";
            var time = setTimeout(function() {
                // 让选中的页面在淡入后消失
                logging[index].style["display"] = "none";
                // 让另一个页面淡出
                logging[1 - index].className = "logging";
            }, 300);
            // 另一个页面淡出后出现
            logging[1 - index].style["display"] = "block";
        })
    }
    //查看所有的用户动态

    //查看动态部分
    var submit33 = document.getElementById("submit33");
    // 向服务端发送请求获取所有用户动态
    submit33.onmousedown = function() {
        ajax({

            type: 'get',
            dataType: 'json',
            url: 'http://www.rushmc.top/api/dynamicState/select/all',
            data: {

            },
            success: function(result) {
                // 检测接口有没有连成功
                if (result.code == 200) {
                    console.log('返回成功');
                    // submit33.className = 'sb sb-success';
                    console.log('success');
                    var searchdy = document.querySelector('.searchdy');
                    var demo9 = document.getElementById('demo9');
                    var demo = document.getElementById('demo');
                    var content = document.querySelector('.content');
                    var content10 = document.querySelector('.content10');
                    var content1 = document.getElementById('content1');
                    var smallbox = document.querySelector('.smallbox');
                    var sticky = document.getElementById('ssb2');
                    content.style.display = 'block';
                    content1.style.display = 'none';
                    smallbox.style.display = 'none';
                    bigbox1.style.display = 'none';
                    content10.style.display = 'none';
                    demo.style.display = 'block';
                    demo9.style.display = 'none';
                    searchdy.style.display = 'none';
                    sticky.style.display = 'none';
                    demo.innerHTML = '';

                    // function split_time(user) {
                    //     //将时间字符串进行分隔
                    //     let push_year_datas = user.creationTime.split("T");
                    //     let push_year = push_year_datas[0];
                    //     let push_time_datas = push_year_datas[1].split(".");
                    //     let push_time = push_time_datas[0];
                    //     let time = push_year + "\xa0\xa0\xa0\xa0" + push_time;
                    //     return time;
                    // }

                    for (let i = 0; i < result.data.length; i++) {
                        var all_consumer_time = timeOperation(result.data[i].creationTime);
                        var div = document.createElement("div");

                        div.id = "slide";
                        // let img = "";
                        if (result.data[i].content == null) {

                            result.data[i].content = "未发布内容";
                        }
                        if (result.data[i].title == null) {

                            result.data[i].title = "未发布标题";
                        }
                        if (result.data[i].content == "undefined") {

                            result.data[i].content = "内容出错"
                        }
                        if (result.data[i].title == "undefined") {

                            result.data[i].title = "标题出错"
                        }
                        if (result.data[i].urls[0] == undefined || result.data[i].urls[0] == null) {
                            div.innerHTML = '<div class="de"><button class="detail">查看详情</button> <li class="zi">标题：' + result.data[i].title + '</li><div class="zi0"><div><img src = "4.jpg"class="imgshow"></div><h5 class="ii">用户id: ' + result.data[i].userId + '</h5><br><h5 class="ii">用户名字：' + result.data[i].username + '</h5><br><h5 class="ii">动态id：' + result.data[i].id + '</h5></div><br><li class="time">' + all_consumer_time + '</li><h5 class="zi1">发布内容：' + result.data[i].content + '......'
                            '</h5></div>'
                            demo.appendChild(div);
                        } else {

                            div.innerHTML = '<div class="de"><button class="detail">查看详情</button> <li class="zi">标题：' + result.data[i].title + '</li><div class="zi0"><div><img src = ' +
                                `http://www.rushmc.top/${ result.data[i].urls[0]}` +
                                ' class="imgshow"></div><h5 class="ii">用户id: ' + result.data[i].userId + '</h5><br><h5 class="ii">用户名字：' + result.data[i].username + '</h5><br><h5 class="ii">动态id：' + result.data[i].id + '</h5></div><br><li class="time">' + all_consumer_time + '</li><h5 class="zi1">发布内容：' + result.data[i].content + '......'
                            '</h5></div>'

                            demo.appendChild(div);
                        }

                    }
                    var div1 = document.querySelectorAll("#slide");
                    var slidebtn = document.querySelectorAll(".detail");
                    var demo1 = document.getElementById('demo1');
                    var content11 = document.getElementById('content1');
                    var sticky = document.getElementById('ssb2');


                    for (let j = 0; j < div1.length; j++) {
                        slidebtn[j].onclick = function() {
                            // var detailc = document.createElement("demo1");
                            demo1.innerHTML = '';
                            content.style.display = 'none';
                            smallbox.style.display = 'none';
                            bigbox1.style.display = 'none';
                            content10.style.display = 'none';
                            demo.style.display = 'none';
                            demo9.style.display = 'none';
                            searchdy.style.display = 'none';
                            content11.style.display = 'block';
                            sticky.style.display = 'block';
                            console.log();
                            if (result.data[j].hasPicture != 0) {
                                let imgLen = result.data[j].urls.length;
                                var imgStr = '';
                                // 将所有图片放到一个个img标签
                                for (let t = 0; t < imgLen; t++) {

                                    imgStr += ` <li class="ImgContent">
                                  <img style="width: 250px;height: 250px;" src= 'http://www.rushmc.top/${ result.data[j].urls[t]}' alt="">
                                  </li>`

                                }
                                // console.log(imgStr);


                            } else if (result.data[j].hasPicture == null || result.data[j].hasPicture == undefined) {
                                imgStr += '该用户未上传照片';
                            }
                            demo1.innerHTML = '<div class="de1"> <li class="zi9">标题：' + result.data[j].title + '</li><div class="zi0"><div></div><h5 class="ii">用户id: ' + result.data[j].userId + '</h5><br><h5 class="ii">用户名字：' + result.data[j].username + '</h5><br><h5 class="ii">动态id：' + result.data[j].id + '</h5></div><br><li class="time">' + all_consumer_time + '</li><h5 class="zi10">发布内容：' + result.data[j].content +
                                '</h5><ul class="imgBox"> ' + `${imgStr}` + '</ul></div>'



                        }
                    }


                } else {
                    console.log('返回错误');

                }
            },
        })
    }

    //向服务器发送请求获得个人动态
    var submit5 = document.getElementById("submit5");
    submit5.onmousedown = function() {

            ajax({

                type: 'get',
                dataType: 'json',
                url: `http://www.rushmc.top/api/dynamicState/select/${user.id}`,
                data: {

                },
                success: function(result) {
                    // 检测接口有没有连成功
                    if (result.code == 200) {
                        console.log('success');
                        console.log(result.data);
                        var demo6 = document.getElementById('demo6');
                        var content10 = document.querySelector('.content10');
                        var content = document.querySelector('.content');
                        // var content1 = document.querySelector('#content1');
                        var smallbox = document.querySelector('.smallbox');
                        content.style.display = 'none';
                        content10.style.display = 'block';
                        smallbox.style.display = 'none';
                        bigbox1.style.display = 'none';
                        demo6.innerHTML = '';

                        // function split_time(user) {
                        //     //将时间字符串进行分隔
                        //     let push_year_datas = user.creationTime.split("T");
                        //     let push_year = push_year_datas[0];
                        //     let push_time_datas = push_year_datas[1].split(".");
                        //     let push_time = push_time_datas[0];
                        //     let time = push_year + "\xa0\xa0\xa0\xa0" + push_time;
                        //     return time;
                        // }

                        for (let i = 0; i < result.data.length; i++) {
                            var all_consumer_time = timeOperation(result.data[i].creationTime);
                            var div = document.createElement("div");

                            div.id = "slide1";
                            // let img = "";
                            if (result.data[i].content == null) {

                                result.data[i].content = "未发布内容";
                            }
                            if (result.data[i].title == null) {

                                result.data[i].title = "未发布标题";
                            }
                            if (result.data[i].content == "undefined") {

                                result.data[i].content = "内容出错"
                            }
                            if (result.data[i].title == "undefined") {

                                result.data[i].title = "标题出错"
                            }
                            if (result.data[i].urls[0] == undefined || result.data[i].urls[0] == null) {
                                div.innerHTML = '<div class="de"><button class="detail">查看详情</button> <li class="zi">标题：' + result.data[i].title + '</li><div class="zi0"><div><img src = "4.jpg"class="imgshow"></div><h5 class="ii">用户id: ' + result.data[i].userId + '</h5><br><h5 class="ii">用户名字：' + result.data[i].username + '</h5><br><h5 class="ii">动态id：' + result.data[i].id + '</h5></div><br><li class="time">' + all_consumer_time + '</li><h5 class="zi1">发布内容：' + result.data[i].content + '......'
                                '</h5></div>'
                                demo6.appendChild(div);
                            } else {

                                div.innerHTML = '<div class="de"><button class="detail">查看详情</button> <li class="zi">标题：' + result.data[i].title + '</li><div class="zi0"><div><img src = ' +
                                    `http://www.rushmc.top/${ result.data[i].urls[0]}` +
                                    ' class="imgshow"></div><h5 class="ii">用户id: ' + result.data[i].userId + '</h5><br><h5 class="ii">用户名字：' + result.data[i].username + '</h5><br><h5 class="ii">动态id：' + result.data[i].id + '</h5></div><br><li class="time">' + all_consumer_time + '</li><h5 class="zi1">发布内容：' + result.data[i].content + '......'
                                '</h5></div>'

                                demo6.appendChild(div);
                            }

                        }
                        var div1 = document.querySelectorAll("#slide1");
                        var slidebtn = document.querySelectorAll(".detail");
                        var demo1 = document.getElementById('demo1');
                        var content11 = document.getElementById('content1');
                        var sticky = document.getElementById('ssb2');
                        var imgStr = '';

                        for (let j = 0; j < div1.length; j++) {
                            slidebtn[j].onclick = function() {
                                // var detailc = document.createElement("demo1");
                                demo1.innerHTML = '';
                                content.style.display = 'none';
                                smallbox.style.display = 'none';
                                bigbox1.style.display = 'none';
                                content10.style.display = 'none';
                                demo.style.display = 'none';
                                demo1.style.display = 'block';
                                demo9.style.display = 'none';
                                searchdy.style.display = 'none';
                                content11.style.display = 'block';
                                sticky.style.display = 'block';
                                // if (state != 200) {
                                //     submit4.style.display = 'none';
                                //     submitim.style.display = 'none';
                                // } else {
                                //     submit4.style.display = 'block';
                                //     submitim.style.display = 'block';
                                // }
                                console.log();
                                if (result.data[j].hasPicture != 0) {
                                    let imgLen = result.data[j].urls.length;
                                    // 将所有图片放到一个个img标签
                                    for (let t = 0; t < imgLen; t++) {
                                        imgStr += ` <li class="ImgContent">
                                      <img style="width: 250px;height: 250px;" src= 'http://www.rushmc.top/${ result.data[j].urls[t]}' alt="">
                                      </li>`

                                    }
                                    // console.log(imgStr);

                                }
                                demo1.innerHTML = '<div class="de1"> <li class="zi9">标题：' + result.data[j].title + '</li><div class="zi0"><div></div><h5 class="ii">用户id: ' + result.data[j].userId + '</h5><br><h5 class="ii">用户名字：' + result.data[j].username + '</h5><br><h5 class="ii">动态id：' + result.data[j].id + '</h5></div><br><li class="time">' + all_consumer_time + '</li><h5 class="zi10">发布内容：' + result.data[j].content +
                                    '</h5><ul class="imgBox"> ' + `${imgStr}` + '</ul></div>'



                            }
                        }
                    } else {
                        console.log('返回错误');

                    }
                },
            })
        }
        //动态搜索用户动态（展示内容不足之处：需要学会用封装处理，减少代码量！）
    var submit00 = document.getElementById("submit00");
    var dycontent = document.getElementById("searchcontent");
    // var key = dycontent.value;
    submit00.onmousedown = function() {
            ajax({

                type: 'get',
                dataType: 'json',
                url: `http://www.rushmc.top/api/dynamicState/search/${dycontent.value}`,
                data: {},
                success: function(result) {
                    // 检测接口有没有连成功
                    if (result.code == 200) {
                        console.log('success');
                        console.log(result.data);
                        var demo = document.getElementById('demo');
                        var content10 = document.querySelector('.content10');
                        var content = document.querySelector('.content');
                        // var content1 = document.querySelector('#content1');
                        var smallbox = document.querySelector('.smallbox');
                        content.style.display = 'block';
                        smallbox.style.display = 'none';
                        bigbox1.style.display = 'none';
                        content10.style.display = 'none';
                        demo.style.display = 'none';
                        demo9.innerHTML = '';
                        document.getElementById("submit00").innerHTML = '查询结果如下';
                        setTimeout(function() {
                            document.getElementById("submit00").innerHTML = '查询相关动态';
                            document.getElementById("searchcontent").innerText = '';
                        }, 2000);
                        for (let i = 0; i < result.data.length; i++) {
                            var all_consumer_time = timeOperation(result.data[i].creationTime);
                            var div = document.createElement("div");

                            div.id = "slide2";
                            // let img = "";
                            if (result.data[i].content == null) {

                                result.data[i].content = "未发布内容";
                            }
                            if (result.data[i].title == null) {

                                result.data[i].title = "未发布标题";
                            }
                            if (result.data[i].content == "undefined") {

                                result.data[i].content = "内容出错"
                            }
                            if (result.data[i].title == "undefined") {

                                result.data[i].title = "标题出错"
                            }
                            if (result.data[i].urls[0] == undefined || result.data[i].urls[0] == null) {
                                div.innerHTML = '<div class="de"><button class="detail1">查看详情</button> <li class="zi">标题：' + result.data[i].title + '</li><div class="zi0"><div><img src = "4.jpg"class="imgshow"></div><h5 class="ii">用户id: ' + result.data[i].userId + '</h5><br><h5 class="ii">用户名字：' + result.data[i].username + '</h5><br><h5 class="ii">动态id：' + result.data[i].id + '</h5></div><br><li class="time">' + all_consumer_time + '</li><h5 class="zi1">发布内容：' + result.data[i].content + '......'
                                '</h5></div>'
                                demo9.appendChild(div);
                            } else {

                                div.innerHTML = '<div class="de"><button class="detail1">查看详情</button> <li class="zi">标题：' + result.data[i].title + '</li><div class="zi0"><div><img src = ' +
                                    `http://www.rushmc.top/${ result.data[i].urls[0]}` +
                                    ' class="imgshow"></div><h5 class="ii">用户id: ' + result.data[i].userId + '</h5><br><h5 class="ii">用户名字：' + result.data[i].username + '</h5><br><h5 class="ii">动态id：' + result.data[i].id + '</h5></div><br><li class="time">' + all_consumer_time + '</li><h5 class="zi1">发布内容：' + result.data[i].content + '......'
                                '</h5></div>'

                                demo9.appendChild(div);
                            }

                        }
                        var div1 = document.querySelectorAll("#slide2");
                        var slidebtn = document.querySelectorAll(".detail1");
                        var demo1 = document.getElementById('demo1');
                        var content12 = document.getElementById('content1');
                        var sticky = document.getElementById('ssb2');
                        // var imgStr = '';

                        for (let j = 0; j < div1.length; j++) {
                            slidebtn[j].onclick = function() {
                                // var detailc = document.createElement("demo1");
                                demo1.innerHTML = '';
                                content.style.display = 'none';
                                smallbox.style.display = 'none';
                                bigbox1.style.display = 'none';
                                demo1.style.display = 'block';
                                content10.style.display = 'none';
                                demo.style.display = 'none';
                                demo9.style.display = 'none';
                                searchdy.style.display = 'none';
                                content12.style.display = 'block';
                                sticky.style.display = 'block';
                                console.log();
                                if (result.data[j].hasPicture) {
                                    let imgLen = result.data[j].urls.length;
                                    var imgStr = '';
                                    // 将所有图片放到一个个img标签
                                    for (let t = 0; t < imgLen; t++) {
                                        imgStr += ` <li class="ImgContent">
                                      <img style="width: 250px;height: 250px;" src= http://www.rushmc.top/${ result.data[j].urls[t]} alt="">
                                      </li>`

                                    }
                                    console.log(imgStr);
                                } else if (result.data[j].hasPicture == null || result.data[j].hasPicture == undefined) {
                                    imgStr += '该用户未上传照片';
                                }

                                demo1.innerHTML = '<div class="de1"> <li class="zi9">标题：' + result.data[j].title + '</li><div class="zi0"><div></div><h5 class="ii">用户id: ' + result.data[j].userId + '</h5><br><h5 class="ii">用户名字：' + result.data[j].username + '</h5><br><h5 class="ii">动态id：' + result.data[j].id + '</h5></div><br><li class="time">' + all_consumer_time + '</li><h5 class="zi10">发布内容：' + result.data[j].content +
                                    '</h5><ul class="imgBox">' + `${imgStr}` + '</ul></div>'



                            }
                        }
                    } else {

                        console.log('返回错误');
                        document.getElementById("submit00").innerHTML = '查询结果为空';
                        setTimeout(function() {
                            document.getElementById("submit00").innerHTML = '查询相关动态';
                            document.getElementById("searchcontent").innerText = '';
                        }, 2000);

                    }
                },
            })
        }
        //定义一个分割时间的函数
    function timeOperation(time) {
        // 获取动态发布的时间对象
        let dynamicTime = new Date(`${time.substr(0, 10)} ${time.substr(11, 8)}`);
        // 获取最新的北京时间
        let bjt = new Date(dynamicTime.getTime() + 8 * 60 * 60000);
        // 处理时间
        let todayTime = new Date();
        let todayDate =
            todayTime.getFullYear() +
            "-" +
            (todayTime.getMonth() + 1) +
            "-" +
            todayTime.getDate();
        // 获取今天零时的时间
        let today = new Date(todayDate).getTime();
        // 显示时间
        let displayTime = "";
        let hour = bjt.getHours() > 9 ? bjt.getHours() : "0" + bjt.getHours();
        let minute = bjt.getMinutes() > 9 ? bjt.getMinutes() : "0" + bjt.getMinutes();
        let socond = bjt.getSeconds() > 9 ? bjt.getSeconds() : "0" + bjt.getSeconds();
        //alert(dynamicTime);
        if (bjt.getTime() > today) {
            displayTime = `今日 ${hour}:${minute}:${socond}`;
        } else if (bjt.getTime() > today - 86400000) {
            displayTime = `昨日 ${hour}:${minute}:${socond}`;
        } else if (bjt.getTime() > today - 172800000) {
            displayTime = `前日 ${hour}:${minute}:${socond}`;
        } else {
            displayTime = `${bjt.getFullYear()}年${
        bjt.getMonth() + 1
      }月${bjt.getDate()}日${hour}:${minute}:${socond}`;
        }
        return displayTime;
    }

    // 获取页面中的元素
    var username = document.getElementById("username");
    var info = document.getElementById("info");
    var password = document.getElementById("password");
    var submit = document.getElementById("submit");
    var submit4 = document.getElementById("submit4");
    var submit5 = document.getElementById("submit5");
    var display1 = document.getElementById("display1");
    var submit4 = document.getElementById('submit4');
    var submitim = document.getElementById('submitim');
    submit4.style.display = 'none';
    submitim.style.display = 'none';

    submit.onmousedown = function() {
            // 获取用户输入的用户名
            var name = username.value;
            var key = password.value;

            // 向服务端发送请求
            ajax({
                type: 'post',
                url: 'http://www.rushmc.top/api/login',
                data: {
                    username: name,
                    password: key
                },
                success: function(result) {
                    // 检测登录有没有成功
                    if (result.code == 200) {
                        display1.innerHTML = '登录啦发表动态';
                        submit4.style.display = 'block';
                        submit5.style.display = 'block';
                        submit.innerHTML = '登录成功';
                        submit.className = 'sb sb-success';
                        submit4.style.display = 'block';
                        submitim.style.display = 'block';
                        state = result.code;
                        user = result.data;
                        Photo = result.data.photo;
                        Phone = result.data.phone;
                        Id = result.data.id;
                        window.localStorage.setItem('Photo', JSON.stringify(result.data.photo));
                        window.localStorage.setItem('Phone', JSON.stringify(result.data.phone));
                        window.localStorage.setItem('Id', JSON.stringify(result.data.id));
                        document.getElementById('name').innerHTML = '亲爱的 ' + result.data.username;
                        document.getElementById('ID').innerHTML = '用户ID：' + Id;
                        document.getElementById('Name').innerHTML = '用户名: ' + result.data.username;
                        document.getElementById('Phone').innerHTML = '手机号码：<br>' + Phone;
                        document.getElementById('namei').innerHTML = '用户：' + result.data.username + '<br>2021-04-23加入';
                        document.getElementById('hname').innerHTML = result.data.username;
                        // let content = JSON.parse(localStorage.getItem('usermsg'));
                        var id = result.data.id;
                        idname = id;
                        var pic1 = document.getElementById('pic1');
                        // var pic2 = document.getElementById('pici');
                        // // pic2.className = 'pic22';
                        // var pic = document.createElement('img');
                        pic1.className = 'pic1';
                        pic1.src = `http://www.rushmc.top/${result.data.photo}`
                            // pic2.src = `http://www.rushmc.top/${result.data.photo}`
                            // document.getElementById('pic1').innerHTML = `<div>$ {result.data.photo}</div>`;
                            // pic1.appendChild(pic);
                        setTimeout(function() {
                            var logging = document.querySelector('.loginarea');
                            var container111 = document.querySelector('.loginarea1');
                            var submit7 = document.querySelector('.closebtn1');
                            submit7.addEventListener('click', function() {
                                    logging.style.display = 'none';
                                    container111.style.display = 'block';

                                })
                                // window.location('success.html');
                            console.log('切换登录');
                        }, 200)

                        // *

                    } else {
                        submit.innerHTML = '账号或密码错误';
                        submit.className = 'sb sb-error';
                        // 重新登录的时候把搜索框调为空
                        setTimeout(function() {
                            username.value = '';
                            password.value = '';
                            submit.innerHTML = '登录';
                            submit.className = 'submit';
                            console.log('清空！！');
                        }, 2000)
                    }
                },
                // error: function(result) {
                //     console.log(result);
                //     info.className = 'bg-danger'
                // }
            })
        }
        // 获取文本框和按钮
    var username_1 = document.getElementById("username_1");
    var password_1 = document.getElementById("password_1");
    var name_1 = document.getElementById("name_1");
    var phone_1 = document.getElementById("phone_1");
    var submit_1 = document.getElementById("submit_1");
    password_1.onblur = function() {
        if (this.value.length < 6 || this.value.length > 16) {
            document.getElementById("ti2").innerHTML = "（×）您输入的密码不符合6~16位";
            ti2.className = 'ti2 wrong';
            setTimeout(function() {
                document.getElementById("ti2").innerHTML = "";
                console.log('清空！！');
            }, 2000)
        } else {
            document.getElementById("ti2").innerHTML = "（√）您输入的密码格式正确";
            ti2.className = 'ti2 right1';
            setTimeout(function() {
                document.getElementById("ti3").innerHTML = "";
                console.log('清空！！');
            }, 2000)
        }
    }
    username_1.onblur = function() {
        if (this.value.length > 6) {
            document.getElementById("ti2").innerHTML = "（×）您输入的用户名要小于6位";
            ti2.className = 'ti2 wrong';
            setTimeout(function() {
                document.getElementById("ti2").innerHTML = "";
                console.log('清空！！');
            }, 2000)
        } else if (this.value.length == 0) {
            document.getElementById("ti2").innerHTML = "（×）您输入的用户名不能为空";
            ti2.className = 'ti2 wrong';
            setTimeout(function() {
                document.getElementById("ti2").innerHTML = "";
                console.log('清空！！');
            }, 2000)
        } else {
            document.getElementById("ti2").innerHTML = "（√）您输入的用户名格式正确";
            ti2.className = 'ti2 right1';
            setTimeout(function() {
                document.getElementById("ti2").innerHTML = "";
                console.log('清空！！');
            }, 2000)
        }
    }
    phone_1.onkeyup = function() {
            var num1 = phone_1.value;
            // 验证电话的正则表达式
            var reg = /^1[34578][0-9]{9}$/;
            // 如果用户输入的电话不符合规则
            if (!reg.test(num1)) {
                console.log("不符合格式");
                info.innerHTML = '请输入符合样式的号码';
                // 让提示信息显示为错误的提示信息样式
                info.className = 'bg bg-error';
                // 阻止程序向下执行
                return;
            } else {
                // 如果电话输入正确提示正确信息，并设置相应样式
                info.innerHTML = '格式正确';
                info.className = 'bg bg-success';
            }

            submit_1.onclick = function() {
                var une1 = username_1.value;
                var key1 = password_1.value;
                var un1 = name_1.value;
                var num1 = phone_1.value;

                ajax({
                    type: 'post',
                    url: 'http://www.rushmc.top/api/register',
                    data: {
                        username: une1,
                        password: key1,
                        name: un1,
                        phone: num1
                    },
                    success: function(result) {
                        console.log(result.msg);
                        // 判断是否注册成功
                        if (result.code == 200) {
                            submit_1.innerHTML = '注册成功，请返回登录界面';
                            submit_1.className = 'sb sb-success';
                            username.value = '';
                            password.value = '';
                        } else {
                            submit_1.innerHTML = '账号已存在,重新注册';
                            submit_1.className = 'sb sb-error';
                            setTimeout(function() {
                                username_1.value = '';
                                password_1.value = '';
                                name_1.value = '';
                                phone_1.value = '';
                                submit_1.className = 'submit';
                                submit_1.innerHTML = '注册';
                                console.log('清空！！');
                            }, 2000)


                        }

                    },
                    // error: function(result) {
                    //     console.log(result);
                    //     submit_1.innerHTML = '注册失败';
                    //     submit_1.className = 'bg-danger';
                    // }
                })
            }
        }
        // 上传头像
    let btn = document.querySelector('#btn')
    let file = document.querySelector('#file')

    btn.onclick = function() {
        file.click() // 调取系统选择图片的弹框
    }

    // 监听input的file变化值
    file.onchange = function(event) {
        let file = event.target.files[0]
        upload(file)
    }

    function upload(file) {
        let xhr = new XMLHttpRequest();
        xhr.open('post', 'http://www.rushmc.top/api/updateAvatar', true)
        let formData = new FormData();
        formData.append('avatar', file);
        formData.append('id', idname);
        var submit55 = document.getElementById("btn");
        xhr.send(formData);
        xhr.onreadystatechange = function() {
            if (xhr.readyState === 4 && xhr.status === 200) {
                var contentType = xhr.getResponseHeader('Content-Type');
                // 服务端返回的数据
                var responseText = xhr.responseText;
                // 如果响应类型中包含的是application/json
                if (contentType.includes('application/json')) {
                    // 将JSON字符串转化为json对象
                    responseText = JSON.parse(responseText);
                }
                var data = responseText;
                console.log(data.data);
                var img = document.querySelector('.pic1');
                img.src = "";
                img.src = "http://www.rushmc.top/" + data.data;
                newPhoto = data.data;
                window.localStorage.setItem('newPhoto', JSON.stringify(data.data));
                console.log('上传成功');
                submit55.innerHTML = '上传成功';
                submit55.className = 'portrait1';
                setTimeout(() => {
                    submit55.innerHTML = '上传头像';
                    submit55.className = 'portrait';
                }, 2500);
            } else {
                console.log('error');
            }
        }

    }

    //删除动态
    let deletebtn1 = document.getElementById("deletebtn1");
    deletebtn1.onclick = function() {
            let xhr = new XMLHttpRequest();
            xhr.open('post', 'http://www.rushmc.top/api/dynamicState/delete', true)
            let formData = new FormData();
            var idname1 = document.getElementById('deleteid');
            if (idname1 != null) {
                formData.append('id', idname1.value);
            } else {
                // setTimeout(function() {
                //     document.getElementById('deletebtn1').innerHTML = '不能为空';
                // }, 1000);
                // document.getElementById('deletebtn1').innerHTML = '删除该动态';
                return;
            }

            var submit55 = document.getElementById("btn");
            xhr.send(formData);
            xhr.onreadystatechange = function() {
                if (xhr.readyState === 4 && xhr.status === 200) {
                    var contentType = xhr.getResponseHeader('Content-Type');
                    // 服务端返回的数据
                    var responseText = xhr.responseText;

                    // 如果响应类型中包含的是application/json
                    if (contentType.includes('application/json')) {
                        // 将JSON字符串转化为json对象
                        responseText = JSON.parse(responseText);
                    }
                    var data1 = responseText;
                    document.getElementById('deletebtn1').innerHTML = data1.msg;
                    setTimeout(function() {
                        document.getElementById('deletebtn1').innerHTML = '删除该动态';
                    }, 2000);
                    console.log(data1.msg);
                } else {
                    console.log('error');
                }
            }

        }
        //封装一个ajax发送动态内容
        //封装的ajax
    var ajax_request = function(url, method, ajax_data) {
            //建立请求对象
            let http = new XMLHttpRequest();
            //向服务器发送请求
            http.open(method, url, true);
            //发送数据
            http.send(ajax_data);
            //当服务器响应时触发
            http.onreadystatechange = function() {
                if (http.readyState == 4 && http.status == 200) {
                    //返回的数据是个字符串，需要调用json.parse方法把他转成js对象
                    let res = JSON.parse(http.responseText);
                    console.log('发送动态成功');
                    document.getElementById("cleaner").innerHTML = "";
                    document.getElementById("cleantitle").innerHTML = "";
                    document.getElementById("cleanpic").innerHTML = "";
                    document.getElementById("post1").innerHTML = "发送成功";
                    setTimeout(function() {
                        document.getElementById("post1").innerHTML = "发送";
                    }, 2500);

                    //判断是所有用户动态的请求
                    if (method === "get") {
                        if (ajax_data == undefined) {
                            console.log(res.data);

                            createDom(res.data);
                        } else {
                            console.log(res.data);
                            create_my_Dom(res.data);
                        }
                    } else {
                        //判断是上传头像发送的请求
                        var photo = ajax_data.get('avatar');
                        if (photo === null) {} else {
                            // change_photo(res.data);
                        }
                        //判断是修改密码发送的请求
                        var password = ajax_data.get('newPassword');
                        // console.log(password);
                        if (password === null) {}
                    }
                }
            }
        }
        //发布我的个人动态
    var my_title_input = document.querySelector('.my_title_input');
    var my_content = document.querySelector('.my_content');
    var add_pic = document.getElementById('add_pic');
    var push_trends_sure = document.querySelector('.push_trends_sure');
    var sticky = document.querySelector('.sticky');
    var pushtrends_delete = document.querySelector('.pushtrends_delete');
    var push_my_trends = document.querySelector('.push_my_trends');
    var hasPicture = 0;


    //上传多张图片并且预览
    var my_pic = document.querySelector('.my_pic');
    var my_pic_box = document.querySelector('.my_pic_box');
    //预览方法
    add_pic.addEventListener("change", setpic, false);

    function setpic() {
        add_pic.style.display = "block";
        for (let i = 0; i < add_pic.files.length; i++) {
            //将文件转换成base64
            let reader_arr = new FileReader();
            reader_arr.readAsDataURL(add_pic.files[i]);
            reader_arr.onload = function() {
                // console.log(this.result);
                //通过base64将图片绝对路径附上去，因为绝对路径一般被浏览器隐藏了
                var path = this.result;
                // setpic(add_pic_len , imgs_path);
                // console.log(add_pic.files[i].name);
                var my_pic_div = document.createElement('div');
                my_pic_div.innerHTML = '<div class="one_in_pic"><img src="' +
                    path + '" alt="" class="one_in_img"></div>'
                my_pic_box.appendChild(my_pic_div);
            }
        }
    }

    //发送
    push_trends_sure.addEventListener('click', function() {
        //判断有无图片
        if (add_pic.files.length != 0) {
            hasPicture = 1
        } else {

        }
        //转换为表单的形式
        let trend_data = new FormData();
        //在data中加入参数，形成表单
        trend_data.append("userId", user.id);
        trend_data.append("content", my_content.innerHTML);
        trend_data.append("title", my_title_input.value);
        trend_data.append("hasPicture", hasPicture);
        for (let i = 0; i < add_pic.files.length; i++) {
            trend_data.append("files", add_pic.files[i]);
            console.log(add_pic.files[i]);
        }
        ajax_request("http://www.rushmc.top/api/dynamicState/insert", "post", trend_data);
    })

    //点击取消按钮后跳转到用户动态界面
    pushtrends_delete.addEventListener('click', function() {
            var sticky = document.getElementById('ssb2');
            document.getElementById("cleaner").innerHTML = "";
            document.getElementById("cleantitle").innerHTML = "";
            document.getElementById("cleanpic").innerHTML = "";
            bigbox1.style.display = 'none';
            smallbox.style.display = 'none';
            content.style.display = 'block';
            content10.style.display = 'none';
            mcontent.style.display = 'none';
            sticky.style.display = 'block';
            demo.style.display = 'block';
            demo9.style.display = 'none';
        })
        //发布动态结束

    //修改密码
    //判断原密码是否正确
    var oldpassword = document.getElementById("op");
    oldpassword.onblur = function() {
            if (this.value == user.password) {
                document.getElementById("ti4").innerHTML = "输入与原密码相符";
                ti4.className = 'ti2 right1';
                setTimeout(function() {
                    document.getElementById("ti4").innerHTML = "";
                    document.getElementById("op").innerHTML = "";
                    ti4.className = '';
                    console.log('清空！！');
                }, 3000)
            } else {
                document.getElementById("ti4").innerHTML = "输入与原密码不相符";
                ti4.className = 'ti2 wrong';
                setTimeout(function() {
                    document.getElementById("ti4").innerHTML = "";
                    document.getElementById("op").innerHTML = "";
                    ti4.className = '';
                    console.log('清空！！');
                }, 3000)
                return
            }
        }
        //对新的密码位数进行判断
    var password_2 = document.getElementById("np");
    password_2.onblur = function() {
        if (this.value.length < 6 || this.value.length > 16) {
            document.getElementById("ti3").innerHTML = "（×）您输入的密码不符合6~16位";
            ti3.className = 'ti2 wrong';
            setTimeout(function() {
                document.getElementById("ti3").innerHTML = "";
                console.log('清空！！');
            }, 2000)
        } else {
            document.getElementById("ti3").innerHTML = "（√）您输入的密码格式正确";
            ti3.className = 'ti2 right1';
            setTimeout(function() {
                document.getElementById("ti3").innerHTML = "";
                console.log('清空！！');
            }, 2000)
        }
    }
    var np = document.getElementById("np");
    var submit8 = document.getElementById("submit8");
    submit8.onmousedown = function() {
        var uid = user.id;
        var np1 = np.value;
        ajax({
            type: 'post',
            url: 'http://www.rushmc.top/api/passwordUpdate',
            data: {
                id: uid,
                newPassword: np1
            },
            header: {
                'Content-Type': 'application/x-www-form-urlencoded'
            },
            success: function(result) {
                console.log(np1);
                console.log(uid);
                // 检测接口有没有连成功
                if (result.code == 200) {
                    document.getElementById("submit8").innerHTML = "修改成功";
                    console.log('修改成功');
                    console.log('success');
                    setTimeout(function() {
                        document.getElementById("submit8").innerHTML = "提交修改";
                    }, 2000);


                } else if (result.code == 300) {
                    console.log('账号不存在');

                }
            }
        })

    }
}